package com.engc.common.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created with IntelliJ IDEA.
 * User: 程钰
 * Date: 13-4-19
 * Time: 下午12:51
 * To change this template use File | Settings | File Templates.
 */
public class BeanUtils {
    /**
     * 按驼峰法转换，把驼峰转换成下划线
     * @param param
     * @return
     */
    public static String camelToUnderline(String param){
        Pattern p=Pattern.compile("[A-Z]");
        if(param==null ||param.equals("")){
            return "";
        }
        StringBuilder builder=new StringBuilder(param);
        Matcher mc=p.matcher(param);
        int i=0;
        while(mc.find()){
            builder.replace(mc.start()+i, mc.end()+i, "_"+mc.group().toLowerCase());
            i++;
        }

        if('_' == builder.charAt(0)){
            builder.deleteCharAt(0);
        }
        return builder.toString().toUpperCase();
    }

}
